package cn.net.cfss.fgbp.face.manage.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author wutao
 * @version 1.0
 * @date 2021/3/12 15:35
 */
@Service
@Slf4j
public class ShareFileUtil {

    @Value("${fgbp.record.folder:/data/share}")
    private String recordFolder;

    @Value("${fgbp.manage.baseUrl:http://172.168.200.79:8015/FGBP-FSC-FACE-MANAGE/recordings/}")
    private String manageBaseUrl;

    /**
     * 将共享文件夹路径下的文件，转换成可以直接通过url访问的路径
     * @param filePath
     * @return
     */
    public String getRecordFold(String filePath) {
        if (StringUtils.isBlank(filePath)) {
            return filePath;
        }
        String newFilePath = filePath.replace(recordFolder, "");
        //如果第一位包含/，移除
        if (newFilePath.startsWith("/")) {
            int startIndex = 1;
            newFilePath = newFilePath.substring(startIndex);
        }
        return manageBaseUrl + newFilePath;
    }
}
